from http.server import CGIHTTPRequestHandler, ThreadingHTTPServer


def run_server(port=9000, bind=""):
    with ThreadingHTTPServer((bind, port), CGIHTTPRequestHandler) as httpd:
        sa = httpd.socket.getsockname()
        serve_message = "Serving HTTP on {host} port {port} (http://{host}:{port}/) ..."
        print(serve_message.format(host=sa[0], port=sa[1]))
        try:
            httpd.serve_forever()
        except KeyboardInterrupt:
            print("\nKeyboard interrupt received, exiting.")
            exit(0)


if __name__ == '__main__':
    run_server()
